<template>
  <div class="searchHistory-container">
    <el-form :model="formData" inline style="display: flex;justify-content: flex-end;margin-top: 10px;">
      <el-form-item prop="userId">
        <el-input v-model="formData.userId" placeholder="请输入用户名Id"></el-input>
      </el-form-item>
      <el-form-item prop="keyword">
        <el-input v-model="formData.keyword" placeholder="请输入关键字"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="search" type="primary">查找</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" border>
      <el-table-column sortable  align="center" label="搜索id" prop="id"></el-table-column>
      <el-table-column align="center" label="用户ID" prop="userId"></el-table-column>
      <el-table-column align="center" label="关键字" prop="keyword"></el-table-column>
      <el-table-column align="center" label="添加时间" prop="addTime"></el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.page"
      :page-sizes="[10, 20, 30, 50, 100]"
      :page-size="pageInfo.limit"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total">
    </el-pagination>
  </div>
</template>
  
<script>
import axios from 'axios'
export default {
  name: 'searchHistory',
  componentTitle: '搜索历史',
  data () {
    return {
      pageInfo: {
        page: 1,
        limit: 20,
        total: 0
      },
       formData: {
         userId: '',
         keyword:''
      },
      tableData: [],
    }
  },
  mounted(){
     this.search()
  },
  methods:{
    search () {
      axios({
        url: 'http://192.168.200.251:8888/admin/history/list',
        method: 'get',
        params: {
          page: this.pageInfo.page,
          limit: this.pageInfo.limit,
          ...this.formData
        },
        headers: {
          'Shopping-Admin-Token': sessionStorage.getItem('Shopping-Admin-Token')
        }
      }).then(res => {
        this.tableData = res.data.data.list

        this.pageInfo.total = res.data.data.total
        console.log(res)
      })
    },
    // 每页多少条切换
    handleSizeChange (value) {
      this.pageInfo.limit = value

      this.search()
    },
    // 当前页码的切换
    handleCurrentChange (value) {
      this.pageInfo.page = value

      this.search()
    }
  }
}
</script>

